<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.bootcss.com/vue/2.6.11/vue.min.js"></script>
</head>
<body>
    <div id="app">
        <foo></foo>
    </div>
    <template id="t1">
        <div>
            Vue子组件 {{msg}}  {{msg2}}  <br>
            <button @click="f1">子组件button</button>
        </div>
    </template>
    <script>
        // Vue私有组件
        var app = new Vue({
            el: "#app",
            data: {
                
            },
            methods: {
              
            },
            components: {   // 直接在Vue父组件中，注册Vue子组件。
                "foo": {
                    template: "#t1",
                    data() {
                        return {
                            msg: "子组件的msg",
                            msg2: "子组件的msg2"
                        }
                    },
                    methods: {
                        f1() {
                            // 注意，这里的this，代表的是子组件，而不是父组件
                            this.msg = "东方不败";
                            this.msg2 = "天山童姥";
                        }
                    }
                }
            }
        });
    </script>
</body>
</html>